﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BusinessRule;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using ProjectManApi.Extensions;

namespace ProjectManApi.Controllers
{

    public class CSController : MvcControllerBase
    {

        [HttpGet("ccc")]
        [AllowAnonymous]
        public IActionResult Index1()
        {
            try
            {
                CsRule.GetcsTrans();

                return Content("成功");
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }

          
        }
        

        //[HttpGet("/[controller]/index")]
        [HttpGet]
        [AllowAnonymous]
        public IActionResult Index()
        {
            

            return Content("11111111111111111");
        }

        //[Authorize(GetUserName = "Permission")]
        [HttpGet]
        public async Task<IActionResult> IndexCSasync()
        {

            //111111
            CsRule csRule = new CsRule();

            var strret = await csRule.GetCS();

            string strjson = JsonConvert.SerializeObject(strret);

            return Success(JsonConvert.DeserializeObject(strjson));
        }


        [HttpGet]
        public async Task<IActionResult> IndexCS3(string apiccount)
        {

            //111111
            CsRule csRule = new CsRule();

            var strret = await csRule.GetCS();

            string strjson = JsonConvert.SerializeObject(strret);

            return Success(JsonConvert.DeserializeObject(strjson));
        }

        [HttpGet]
        public async Task<IActionResult> IndexCS4(string apiccount)
        {

            //111111
            CsRule csRule = new CsRule();

            var strret = await csRule.GetCS();

            string strjson = JsonConvert.SerializeObject(strret);

            return Success(JsonConvert.DeserializeObject(strjson));
        }

        //这个查询会报错， 因为查询结果还没出来，所以，所有查询都必须在最外层 async 异步
        [HttpGet]
        public IActionResult IndexCS2()
        {
            CsRule csRule = new CsRule();

            var strret = csRule.GetCS2();

            string strjson = JsonConvert.SerializeObject(strret);

            return Success(JsonConvert.DeserializeObject(strjson));
        }
    }
}